﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Bee.Web;
using System.Timers;
using System.Web;
using Bee.Logging;
using Bee.Util;

namespace Bee.Admin
{
    public class BeeAdminController : ControllerBase
    {
        private static readonly int Port = NetworkUtil.GetAvailablePort(2012);
        static BeeAdminController()
        {
            WebSocketManager.Instance.Start(Port);
            Logger.Init(new AdminLogImpl());

            AppDomain.CurrentDomain.DomainUnload += new EventHandler(CurrentDomain_DomainUnload);
        }

        static void CurrentDomain_DomainUnload(object sender, EventArgs e)
        {
            WebSocketManager.Instance.Stop();
        }

        public PageResult Index()
        {
            ViewData["url"] = "ws://{0}:{1}".FormatWith(HttpContextUtil.Host, Port);

            return View();
        }
    }
}
